package com.ss.android.newmedia.e;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Base64;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.common.utility.collection.WeakList;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.account.Spipe;
import com.ss.android.account.activity.AuthorizeActivity;
import com.ss.android.account.c.QZone;
import com.ss.android.article.browser.R;
import com.ss.android.common.AppContext;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.app.permission.PermissionsManager;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.download.DownloadAdapterProxy;
import com.ss.android.common.download.DownloadInfoChangeListener;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.LoadUrlUtils;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.http.legacy.a.NameValueImpl;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.loader.LargeImageCtxRef;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.a.w;
import com.ss.android.newmedia.activity.browser.BrowserActivity;
import com.ss.android.newmedia.f.k;
import com.ss.android.newmedia.util.AppUtil;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX.Req;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.Inflater;

public class JsObject implements Callback {
    private static final String TAG = JsObject.class.getSimpleName();
    public static WeakList sInsts;
    public static Map HOST_SET;
    private static byte[] sDecodeBuf;

    static {
        JsObject.sInsts = new WeakList();
        JsObject.HOST_SET = new ConcurrentHashMap();
        JsObject.sDecodeBuf = new byte[8192];
        JsObject.HOST_SET.put("log_event", Boolean.TRUE);
        JsObject.HOST_SET.put("log_event_v3", Boolean.TRUE);
        JsObject.HOST_SET.put("download_app", Boolean.TRUE);
        JsObject.HOST_SET.put("disable_swipe", Boolean.TRUE);
        JsObject.HOST_SET.put("disable_overlay", Boolean.TRUE);
        JsObject.HOST_SET.put("view_image_list", Boolean.TRUE);
        JsObject.HOST_SET.put("refresh_user_info", Boolean.TRUE);
        JsObject.HOST_SET.put("close_current_page", Boolean.TRUE);
        JsObject.HOST_SET.put("private", Boolean.TRUE);
        JsObject.HOST_SET.put("dispatch_message", Boolean.TRUE);
        JsObject.HOST_SET.put("domReady", Boolean.TRUE);
    }

    private final JSONArray mFeatureList;
    private final JSONArray mLegacyFeatureList;
    public BaseAppData mAppData;
    public WeakReference<Context> mContextRef;
    public WeakReference<Fragment> mFragmentRef;
    public ContextDataProvider mJsDataProvider;
    public GalleryDisplayer mGalleryDisplayer;
    protected Map<Long, DownloadInfoChangeListener> webDownloadlisteners;
    private Handler mWeakHandler;
    private IWXAPI mWxApi;
    private boolean B;
    private WeakReference b;
    private WeakReference mGeoDlg;
    private boolean mFeatureListInited;
    private HashMap<String, List<String>> mFeatureMap;
    private WeakReference mLargeImgeCtxRef;
    private m mConfigHelper;
    private String mPendingConfigKey;
    private String mPendingConfigCallback;
    private k mLastConfigItem;
    private long mLastRefreshUserTime;
    private String mPendingLoginPlat;
    private String mPendingLoginCallbackId;
    private int mPendingShareId;

    public JsObject(BaseAppData baseAppData, Context context) {
        this.mFeatureList = new JSONArray();
        this.mLegacyFeatureList = new JSONArray();
        this.mFeatureListInited = false;
        this.mFeatureMap = new HashMap();
        this.webDownloadlisteners = new HashMap();
        this.mLastConfigItem = null;
        this.mLastRefreshUserTime = 0;
        this.mPendingLoginPlat = null;
        this.mPendingLoginCallbackId = null;
        this.mPendingShareId = 0;
        this.B = false;
        this.mAppData = baseAppData;
        this.mContextRef = new WeakReference(context);
        this.mWeakHandler = new WeakHandler(Looper.getMainLooper(), this);
        if (context != null) {
            this.mConfigHelper = com.ss.android.newmedia.e.m.a(context);
        }
        JsObject.sInsts.add(this);
    }

    private static int extractImageList(Uri uri, List<ImageInfo> imageInfoList) {
        String v2_1;
        int v1_4;
        byte[] v3;
        Inflater v2;
        String v1_1;
        int v0 = 0;
        try {
            v1_1 = uri.getQueryParameter("data");
            if (android.support.design.a.isTextEmpty(v1_1)) {
                return v0;
            }

            byte[] bytes = Base64.decode(v1_1, 8);
            v2 = new Inflater();
            v2.setInput(bytes);
            v3 = JsObject.sDecodeBuf;
            synchronized (v3) {
                v1_4 = v2.inflate(JsObject.sDecodeBuf);
                v2.end();
                if (v1_4 <= 0 || v1_4 >= 8192) {
                    return v0;
                }

                v2_1 = new String(JsObject.sDecodeBuf, 0, v1_4, "UTF-8");
            }
            JSONArray v3_1 = new JSONArray(v2_1);
            int v2_2 = v3_1.length();
            for (v1_4 = 0; v1_4 < v2_2; ++v1_4) {
                imageInfoList.add(ImageInfo.fromJson(v3_1.getJSONObject(v1_4), false));
            }

            v1_1 = uri.getQueryParameter("index");
            if (android.support.design.a.isTextEmpty(v1_1)) {
                return v0;
            }

            return Integer.parseInt(v1_1);
        } catch (Exception v1) {
            Logger.w(JsObject.TAG, "view_image_list exception: " + v1);
            return v0;
        }
    }

    static void onJsConfigLoaded(String arg7, k arg8, String arg9) {
        int v1_2;
        String v6;
        JSONObject v5;
        String v2 = null;
        if (Logger.debug()) {
            Logger.d(JsObject.TAG, "onJsConfigLoaded " + arg7);
        }

        Iterator v3 = JsObject.sInsts.iterator();
        while (v3.hasNext()) {
            Object v0 = v3.next();
            if (v0 == null) {
                continue;
            }

            if (arg7 == null) {
                continue;
            }

            if (!arg7.equals(((JsObject) v0).mPendingConfigKey)) {
                continue;
            }

            if (android.support.design.a.isTextEmpty(((JsObject) v0).mPendingConfigCallback)) {
                continue;
            }

            String v4 = ((JsObject) v0).mPendingConfigCallback;
            ((JsObject) v0).mPendingConfigKey = v2;
            ((JsObject) v0).mPendingConfigCallback = v2;
            WebView v1 = ((JsObject) v0).getWebView();
            String v1_1 = v1 != null ? v1.getUrl() : v2;
            if (android.support.design.a.isTextEmpty(v1_1)) {
                continue;
            }

            if (!TTUtils.isValidUrl(v1_1)) {
                continue;
            }

            try {
                v1_1 = Uri.parse(v1_1).getHost();
                if (v1_1 == null) {
                    continue;
                }

                if (!v1_1.equals(arg9)) {
                    continue;
                }

                v5 = new JSONObject();
                v6 = "code";
                if (arg8 != null) {
                    v1_2 = 1;
                } else {
                    v1_2 = 0;
                }
                v5.put(v6, v1_2);
                ((JsObject) v0).mLastConfigItem = arg8;
                ((JsObject) v0).sendCallbackMsg(v4, v5);
            } catch (Exception v0_1) {
                v0_1.printStackTrace();
            }
        }
    }

    public static boolean canHandleUri(Uri uri) {
        boolean v0 = false;
        if (uri != null) {
            try {
                if (!"bytedance".equals(uri.getScheme())) {
                    return v0;
                }

                if (!JsObject.HOST_SET.containsKey(uri.getHost())) {
                    return v0;
                }
            } catch (Exception v1) {
                return v0;
            }

            v0 = true;
        }

        return v0;
    }

    public static void e() {
    }

    private void doShare(ShareBean arg13) {
        String v0 = arg13.platform;
        String v2 = arg13.title;
        String v3 = arg13.desc;
        String v4 = arg13.url;
        String v9 = null;
        if (TTUtils.isValidUrl(arg13.image)) {
            v9 = arg13.image;
        }

        byte[] v5 = arg13.h;
        String v10 = arg13.i;
        if ("weixin".equals(v0)) {
            this.handleWeixinShare(false, v2, v3, v4, v5);
        } else if ("weixin_moments".equals(v0)) {
            this.handleWeixinShare(true, v2, v3, v4, v5);
        } else {
            if (!"qzone_sns".equals(v0) && !"qzone".equals(v0)) {
                if ("qq".equals(v0)) {
                    this.handleQQShare(false, v2, v3, v9, v10, v4);
                } else {
                }

                return;
            }

            this.handleQQShare(true, v2, v3, v9, v10, v4);
        }
    }

    private void handleWeixinShare(boolean arg7, String arg8, String arg9, String arg10, byte[] arg11) {
        int v2 = R.drawable.close_popup_textpage;
        Object v0 = this.mContextRef != null ? this.mContextRef.get() : null;
        if (v0 != null) {
            if (!this.isWXAppInstalled()) {
                UIUtils.showImageToast(((Context) v0), v2, R.string.toast_weixin_not_install);
            } else if (!this.initWx()) {
                UIUtils.showImageToast(((Context) v0), v2, R.string.toast_weixin_not_available);
            } else {
                int v0_1 = arg7 ? 1 : 0;
                WXWebpageObject v1 = new WXWebpageObject();
                v1.webpageUrl = arg10;
                WXMediaMessage v2_1 = new WXMediaMessage();
                v2_1.mediaObject = ((IMediaObject) v1);
                v2_1.title = arg8;
                v2_1.description = arg9;
                if (arg11 != null) {
                    v2_1.thumbData = arg11;
                }

                Req v1_1 = new Req();
                v1_1.transaction = String.valueOf(System.currentTimeMillis());
                v1_1.scene = v0_1;
                v1_1.message = v2_1;
                this.mWxApi.sendReq(((BaseReq) v1_1));
            }
        }
    }

    private void handleQQShare(boolean arg8, String arg9, String arg10, String arg11, String arg12, String arg13) {
        Object v1 = null;
        Object v0 = this.mContextRef != null ? this.mContextRef.get() : v1;
        if (v0 != null) {
            if (!(v0 instanceof Activity)) {
                v0 = v1;
            }

            if (v0 == null) {
                return;
            }

            if (!QZone.a(((Context) v0))) {
                UIUtils.showImageToast(((Context) v0), R.drawable.close_popup_textpage, R.string.toast_qq_not_install);
                return;
            }

            String v6 = ((Activity) v0).getString(com.ss.android.article.browser.R.string.app_name);
            new StringBuilder().append(v6).append(QZone.a());
            if (arg8) {
                QZone.b(((Context) v0), arg13, arg9, arg10, arg11, arg12, v6);
                return;
            }

            QZone.a(((Context) v0), arg13, arg9, arg10, arg11, arg12, v6);
        }
    }

    public final void sendCallbackMsg(String callbackId, JSONObject arg5) {
        try {
            JSONObject v0_1 = new JSONObject();
            v0_1.put("__msg_type", "callback");
            v0_1.put("__callback_id", callbackId);
            if (arg5 != null) {
                v0_1.put("__params", arg5);
            }
            this.sendJsMessage(v0_1);
        } catch (Exception v0) {
        }
    }

    private void getAppInfo(JSONObject arg6, int arg7, k arg8, boolean arg9) throws Exception {
        boolean v0_3;
        boolean v1 = true;
        if (!this.mFeatureListInited) {
            this.mFeatureListInited = true;
            try {
                Iterator v3 = this.getFeature("public").iterator();
                while (v3.hasNext()) {
                    this.mFeatureList.put(v3.next());
                }

                v3 = this.getFeature("protected").iterator();
                while (v3.hasNext()) {
                    this.mFeatureList.put(v3.next());
                }

                v3 = this.getFeature("legacy").iterator();
                while (v3.hasNext()) {
                    this.mLegacyFeatureList.put(v3.next());
                }
            } catch (Exception v0) {
            }
        }

        AppContext appContext = this.mAppData.getAppContext();
        String v0_1 = this.getJSAppName();
        if (android.support.design.a.isTextEmpty(v0_1)) {
            v0_1 = appContext.getAppName();
        }

        arg6.put("appName", v0_1);
        arg6.put("aid", appContext.getAid());
        v0_1 = AppLog.p();
        if (android.support.design.a.isTextEmpty(v0_1)) {
            v0_1 = appContext.getVersion();
        }

        arg6.put("appVersion", v0_1);
        arg6.put("versionCode", appContext.getVersionCode());
        arg6.put("netType", NetworkUtils.getNetworkAccessType(appContext.getContext()));
        String v3_2 = "supportList";
        JSONArray v0_2 = arg7 <= 1 ? this.mLegacyFeatureList : this.mFeatureList;
        arg6.put(v3_2, v0_2);
        if (arg9) {
            v0_3 = true;
        } else if (arg8 != null) {
            v1 = arg8.c.contains("device_id");
            v0_3 = arg8.c.contains("user_id");
        } else {
            v0_3 = false;
            v1 = false;
        }

        String v2 = AppLog.deviceId();
        if ((v1) && !android.support.design.a.isTextEmpty(v2)) {
            arg6.put("device_id", v2);
        }

        Spipe v1_1 = Spipe.inst();
        if ((v1_1.isLogin) && (v0_3)) {
            arg6.put("user_id", v1_1.userId);
        }

        if (arg8 != null && (Logger.debug())) {
            JSONArray v1_2 = new JSONArray();
            Iterator v2_1 = arg8.b.iterator();
            while (v2_1.hasNext()) {
                v1_2.put(v2_1.next());
            }

            arg6.put("callList", v1_2);
            v1_2 = new JSONArray();
            v2_1 = arg8.c.iterator();
            while (v2_1.hasNext()) {
                v1_2.put(v2_1.next());
            }

            arg6.put("infoList", v1_2);
        }
    }

    public String getJSAppName() {
        return null;
    }

    private boolean config(String arg13, JSONObject arg14, JSONObject arg15) throws Exception {
        k v0_2 = null;
        boolean v0_1;
        String v2_1 = null;
        String v1;
        String v0 = null;
        if (arg14 == null) {
            v1 = v0;
        } else if (arg14.has("client_id")) {
            v1 = arg14.optString("client_id");
        } else {
            v1 = arg14.optString("clientID");
        }

        if (!android.support.design.a.isTextEmpty(v1) && this.mConfigHelper != null) {
            WebView v2 = this.getWebView();
            v0 = v2 != null ? v2.getUrl() : null;
            if (!android.support.design.a.isTextEmpty(v0) && v2 != null) {
                try {
                    v2_1 = Uri.parse(v0).getHost();
                } catch (Exception v3) {
                }

                if (this.a(v0)) {
                    arg15.put("code", 1);
                    v0_1 = true;
                } else if (!TTUtils.isValidUrl(v0)) {
                    v0_1 = false;
                } else {
                    m v3_1 = this.mConfigHelper;
                    String v4 = com.ss.android.newmedia.f.k.a(v2_1, v1);
                    if (android.support.design.a.isTextEmpty(v4)) {
                        v0_2 = v3_1.c;
                    } else {
                        Object v0_3 = v3_1.b.get(v4);
                        long v6 = System.currentTimeMillis();
                        boolean v5 = NetworkUtils.isNetworkAvailable(v3_1.a);
                        if (v0_3 != null) {
                            if (v6 - ((k) v0_3).a < 600000) {
//                                goto label_53;
                            } else if (!v5) {
                                if (v6 - ((k) v0_3).a >= 1200000) {
                                    label_77:
                                    if (v5) {
                                        v3_1.d.addTask(v4, v2_1, v1, null);
                                    }

                                    v0_2 = null;
                                } else {
//                                goto label_53;
                                }
                            } else {
                                label_77:
                                if (v5) {
                                    v3_1.d.addTask(v4, v2_1, v1, null);
                                }

                                v0_2 = null;
                            }
                        } else {
                            label_77:
                            if (v5) {
                                v3_1.d.addTask(v4, v2_1, v1, null);
                            }

                            v0_2 = null;
                        }


                    }

//                    label_53:
                    if (v0_2 == null && !NetworkUtils.isNetworkAvailable(this.getActivityCtx())) {
                        arg15.put("code", 0);
                        return true;
                    }

                    if (v0_2 != null) {
                        this.mLastConfigItem = v0_2;
                        arg15.put("code", 1);
                        return true;
                    }

                    this.mPendingConfigKey = com.ss.android.newmedia.f.k.a(v2_1, v1);
                    this.mPendingConfigCallback = arg13;
                    v0_1 = false;
                }

                return v0_1;
            }

            arg15.put("code", 0);
            v0_1 = true;
        } else {
            arg15.put("code", 0);
            v0_1 = true;
        }

        return v0_1;
    }

    public boolean a(String arg2) {
        return false;
    }

    public void addProtectedFeature(List<String> arg2) {
        arg2.add("isAppInstalled");
        arg2.add("share");
        arg2.add("open");
        arg2.add("openThirdApp");
        arg2.add("copyToClipboard");
    }

    public void a(JSONObject arg1) {
    }

    public boolean a(Context arg2) {
        return arg2 instanceof BrowserActivity;
    }

    public void handleUri(Uri arg11) {
        String v9;
        Object v1_1;
        Object v0_2;
        JSONObject v4_1;
        JSONObject v3_1;
        long v4;
        String v3;
        String v2;
        String v1;
        long v6 = 0;
        JSONObject v8 = null;
        try {
            String v0_1 = arg11.getHost();
            if (!"log_event".equals(v0_1)) {
                if (!"log_event_v3".equals(v0_1)) {
                    label_56:
                    if (!"download_app".equals(v0_1)) {
//                goto label_107;
                    } else {
                        v1 = arg11.getQueryParameter("app_name");
                        v2 = arg11.getQueryParameter("download_url");
                        v3_1 = new JSONObject();
                        v4_1 = new JSONObject();
                        v4_1.put("url", v2);
                        if (this.b != null && this.b.get() != null) {
                            v4_1.put("referer_url", ((WebView) this.b.get()).getUrl());
                        }
                        v3_1.put("label", "jsbridge");
                        v3_1.put("ext_json", v4_1);
                        if (Build.VERSION.SDK_INT >= 23) {
                            if (!(this.mContextRef.get() instanceof Activity)) {
                                return;
                            }

                            PermissionsManager.getInstance().requestPermission((Activity) this.mContextRef.get(), new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, new j(this, v2, v1, v3_1));
                            return;
                        }
                        AppUtil.a(v2, v1, (Context) this.mContextRef.get(), v3_1);
                        return;
                    }
//            label_107:
                    if (!"disable_swipe".equals(v0_1)) {
                        if (!"view_image_list".equals(v0_1)) {
                            if ("refresh_user_info".equals(v0_1)) {
                                long v0_3 = System.currentTimeMillis();
                                long v2_1 = v0_3 - this.mLastRefreshUserTime;
                                if (this.mContextRef == null) {
                                    return;
                                }

                                if (this.mContextRef.get() == null) {
                                    return;
                                }

                                if (v2_1 <= 3000) {
                                    return;
                                }

                                this.mLastRefreshUserTime = v0_3;
                                Spipe.inst().b((Context) this.mContextRef.get());
                                return;
                            }

                            if ("close_current_page".equals(v0_1)) {
                                this.c((JSONObject) null);
                                return;
                            }

                            if (!"private".equals(v0_1) && !"dispatch_message".equals(v0_1)) {
                                return;
                            }

                            this.parseMsgQueue(arg11.toString());
                            return;
                        }
                        if (this.mLargeImgeCtxRef != null) {
                            v1_1 = this.mLargeImgeCtxRef.get();
                        } else {
//                goto label_145;
                            v1_1 = v8;
                        }
                        if (v1_1 == null) {
                            if (this.mContextRef != null) {
                                v0_2 = this.mContextRef.get();
                            } else {
                                v0_2 = v8;
                            }
                            boolean v2_2 = v0_2 instanceof LargeImageCtxRef;
                            if (!v2_2) {
                                v0_2 = v1_1;
                            }

                            if (v0_2 == null) {
                                return;
                            }
                        } else {
                            v0_2 = v1_1;
                            if (v0_2 == null) {
                                return;
                            }
                        }

                        ArrayList v1_3 = new ArrayList();
                        int v2_3 = JsObject.extractImageList(arg11, ((List) v1_3));
                        if (((List) v1_3).isEmpty()) {
                            return;
                        }

                        ((LargeImageCtxRef) v0_2).startThumbPreviewActivity(((List) v1_3), v2_3);
                        return;
                    }

                    if (this.mContextRef != null) {
                        v0_2 = this.mContextRef.get();
                    } else {
                        v0_2 = v8;
                    }
                    boolean v1_2 = v0_2 instanceof w;
                    if (!v1_2) {
                        return;
                    }

                    ((w) v0_2).disableOverlaySwipe();
                    return;
                }

                v1 = arg11.getQueryParameter("event");
                v2 = arg11.getQueryParameter("params");
                if (android.support.design.a.isTextEmpty(v2)) {
                    android.support.design.a.onEvent(v1, v8);
                    return;
                }
                v8 = new JSONObject(v2);
                android.support.design.a.onEvent(v1, v8);
                return;
            }

            v1 = arg11.getQueryParameter("category");
            v2 = arg11.getQueryParameter("tag");
            v3 = arg11.getQueryParameter("label");
            v4 = Long.parseLong(arg11.getQueryParameter("value"));
            v6 = Long.parseLong(arg11.getQueryParameter("ext_value"));
            v9 = arg11.getQueryParameter("extra");
            if (android.support.design.a.isTextEmpty(v9)) {
                MobAdClickCombiner.onAdEvent((Context) this.mContextRef.get(), v1, v2, v3, v4, v6, v8, 4);
                return;
            }
            v8 = new JSONObject(v9);
            MobAdClickCombiner.onAdEvent((Context) this.mContextRef.get(), v1, v2, v3, v4, v6, v8, 4);
            return;
        } catch (Exception v0) {
            Logger.w(JsObject.TAG, "handleUri exception: " + v0);
        }
    }

    public final void setFragment(Fragment arg2) {
        this.mFragmentRef = arg2 != null ? new WeakReference(arg2) : null;
    }

    public final void setWebView(WebView arg2) {
        this.b = new WeakReference(arg2);
    }

    public final void setLargeImageContext(LargeImageCtxRef imageCtxRef) {
        this.mLargeImgeCtxRef = null;
        if (imageCtxRef != null) {
            this.mLargeImgeCtxRef = new WeakReference(imageCtxRef);
        }
    }

    public final void addDownloadListener(Long arg8, String arg9) {
        if (this.webDownloadlisteners == null) {
            this.webDownloadlisteners = new HashMap();
        }

        if (this.getActivityCtx() != null && arg8 != null && !android.support.design.a.isTextEmpty(arg9)) {
            i$a v3 = new i$a(this);
            DownloadAdapterProxy.inst().registerDownloadListener(this.getActivityCtx(), arg8, ((DownloadInfoChangeListener) v3), arg9, 4, null);
            this.webDownloadlisteners.put(arg8, v3);
        }
    }

    public final void onGeolocationPermissionsShowPrompt(String arg6, GeolocationPermissions.Callback arg7) {
        if (!android.support.design.a.isTextEmpty(arg6) && arg7 != null) {
            Activity v1 = this.getActivityCtx();
            if (v1 != null) {
                Object v0 = this.mGeoDlg != null ? this.mGeoDlg.get() : null;
                if (v0 != null && (((AlertDialog) v0).isShowing())) {
                    ((AlertDialog) v0).dismiss();
                }

                AlertDialog.Builder builder = com.ss.android.j.b.createDialogBuilder(((Context) v1));
                builder.setTitle(com.ss.android.article.browser.R.string.geo_dlg_title);
                builder.setMessage(v1.getString(com.ss.android.article.browser.R.string.geo_dlg_message, new Object[]{arg6}));
                com.ss.android.newmedia.e.k v1_1 = new com.ss.android.newmedia.e.k(arg7, arg6);
                builder.setNegativeButton(com.ss.android.article.browser.R.string.geo_dlg_disallow, ((DialogInterface.OnClickListener) v1_1));
                builder.setPositiveButton(com.ss.android.article.browser.R.string.geo_dlg_allow, ((DialogInterface.OnClickListener) v1_1));
                builder.setCancelable(false);
                this.mGeoDlg = new WeakReference(builder.show());
            }
        }
    }

    public boolean processJsMsg(JSMessage jsMessage, JSONObject arg11) throws Exception {
        Intent v0_2;
        int v0_1;
        String v1_1;
        String v0_4;
        Object v0 = null;
        int v3 = -1;
        int v2 = 0;
        boolean v1 = true;
        String func = jsMessage.func;
        JSONObject params = jsMessage.params;
        if (!"isAppInstalled".equals(func)) {
            if ("close".equals(func)) {
                this.c(params);
                return false;
            }

            if ("open".equals(func)) {
                this.e(jsMessage.params);
                arg11.put("code", 1);
                return v1;
            }

            if ("gallery".equals(func)) {
                if (this.showGallery(params)) {
                    arg11.put("code", 1);
                    return v1;
                }

                arg11.put("code", 0);
                return v1;
            }

            if ("share".equals(func)) {
                if (android.support.design.a.isComponentActive(this.getActivityCtx())) {
                    arg11.put("code", 1);
                    ShareBean v0_3 = new ShareBean();
                    v0_3.fromJSONObject(params);
                    if (android.support.design.a.isTextEmpty(v0_3.platform)) {
                        return v1;
                    }

                    if (android.support.design.a.isTextEmpty(v0_3.url)) {
                        return v1;
                    }

                    this.a(v0_3.platform, v0_3);
                    return v1;
                }

                arg11.put("code", 0);
                return v1;
            }

            if ("login".equals(func)) {
                String v3_1 = jsMessage.callbackId;
                Activity v4_2 = this.getActivityCtx();
                if (v4_2 != null) {
                    v0_4 = params.optString("platform");
                    if (android.support.design.a.isTextEmpty(v0_4)) {
                        label_174:
                        v1_1 = v0_4;
                    } else if ("weibo".equals(v0_4)) {
                        v1_1 = "sina_weibo";
                    } else if ("qq".equals(v0_4)) {
                        v1_1 = "qzone_sns";
                    } else {
                        v1_1 = v0_4;
                    }

                    if (android.support.design.a.isTextEmpty(v1_1)) {
                        v0 = ComponentsManifest.findComponent(com.ss.android.account.v2.bb.class);
                        Bundle v6_1 = new Bundle();
                        v6_1.putString("extra_title_type", params.optString("title_type"));
                        v6_1.putString("extra_source", params.optString("login_source"));
                        ((com.ss.android.account.v2.bb) v0).startAccountLoginActivity(v4_2, v6_1);
                    } else {
                        v0_2 = new Intent(v4_2, AuthorizeActivity.class);
                        v0_2.putExtra("platform", v1_1);
                        v4_2.startActivity(v0_2);
                    }

                    if (android.support.design.a.isTextEmpty(v3_1)) {
                        return false;
                    }
                    this.mPendingLoginCallbackId = v3_1;
                    this.mPendingLoginPlat = v1_1;
                }
                return false;
            }

            if ("copyToClipboard".equals(func)) {
                if (params != null) {
                    v0_4 = params.optString("content");
                }

                Activity v3_2 = this.getActivityCtx();
                if (v3_2 != null && !android.support.design.a.isTextEmpty(((String) v0))) {
                    com.bytedance.common.utility.a.a.a(((Context) v3_2), "", ((CharSequence) v0));
                    v2 = 1;
                }

                arg11.put("code", v2);
                return v1;
            }

            if ("openThirdApp".equals(func)) {
                if (this.f(params)) {
                    arg11.put("code", 1);
                    return v1;
                }

                arg11.put("code", 0);
                return v1;
            }

            v1 = false;
        } else if (params == null) {
            arg11.put("installed", v3);
        } else {
            String v6 = params.optString("pkg_name");
            String v5_1 = params.optString("open_url");
            Object v4_1 = this.mContextRef != null ? this.mContextRef.get() : v0;
            if (v4_1 != null) {
                if (android.support.design.a.isTextEmpty(v6)) {
                    v0_1 = v3;
                } else if (ToolUtils.isAppInstalled(((Context) v4_1), v6)) {
                    v0_1 = 1;
                } else {
                    v0_1 = 0;
                }

                if (v0_1 == 1) {
//                    goto label_39;
                } else if (android.support.design.a.isTextEmpty(v5_1)) {
//                    goto label_39;
                } else {
                    v0_2 = new Intent("android.intent.action.VIEW");
                    v0_2.setData(Uri.parse(v5_1));
                    if (ToolUtils.isInstalledApp(((Context) v4_1), v0_2)) {
                        v0_1 = 1;
//                      goto label_39;
                    } else {
                        v0_1 = 0;
                    }
                }
            } else {
                v0_1 = v3;
            }

            label_39:
            arg11.put("installed", v0_1);
        }

        return v1;
    }

    public final boolean a(String platform, ShareBean shareBean) {
        boolean v0_1;
        int v4 = R.drawable.close_popup_textpage;
        Context context = this.mContextRef != null ? this.mContextRef.get() : null;
        if (context == null) {
            v0_1 = false;
        } else {
            if (("weixin".equals(platform)) || ("weixin_moments".equals(platform))) {
                if (!this.isWXAppInstalled()) {
                    UIUtils.showImageToast(((Context) context), v4, R.string.toast_weixin_not_install);
                    return true;
                }

                if (this.initWx()) {
                    if (android.support.design.a.isTextEmpty(shareBean.image)) {
                        this.doShare(shareBean);
                        return true;
                    }

                    ++this.mPendingShareId;
                    shareBean.a = this.mPendingShareId;
                    ProgressDialog progressDialog = new ProgressDialog(((Context) context));
                    progressDialog.setMessage(((Context) context).getString(com.ss.android.article.browser.R.string.tip_prepare_image_for_share));
                    progressDialog.setCancelable(true);
                    progressDialog.show();
                    shareBean.g = new WeakReference(progressDialog);
                    this.mWeakHandler.sendMessageDelayed(this.mWeakHandler.obtainMessage(12, shareBean), 3500);
                    new f(((Context) context).getApplicationContext(), this.mWeakHandler, shareBean).execute(new Object[0]);
                    v0_1 = true;
                    return v0_1;
                }

                UIUtils.showImageToast(((Context) context), v4, R.string.toast_weixin_not_available);
                v0_1 = true;
            } else {
                if (!"qzone_sns".equals(platform) && !"qzone".equals(platform) && !"qq".equals(platform)) {
                    return false;
                }

                if (QZone.a(((Context) context))) {
                    label_47:
                    if (android.support.design.a.isTextEmpty(shareBean.image)) {
                        this.doShare(shareBean);
                        return true;
                    }

                    ++this.mPendingShareId;
                    shareBean.a = this.mPendingShareId;
                    ProgressDialog progressDialog = new ProgressDialog(((Context) context));
                    progressDialog.setMessage(((Context) context).getString(com.ss.android.article.browser.R.string.tip_prepare_image_for_share));
                    progressDialog.setCancelable(true);
                    progressDialog.show();
                    shareBean.g = new WeakReference(progressDialog);
                    this.mWeakHandler.sendMessageDelayed(this.mWeakHandler.obtainMessage(12, shareBean), 3500);
                    new f(((Context) context).getApplicationContext(), this.mWeakHandler, shareBean).execute(new Object[0]);
                    v0_1 = true;
                    return v0_1;
                }

                UIUtils.showImageToast(((Context) context), v4, R.string.toast_qq_not_install);
                v0_1 = true;
            }
            return v0_1;


        }

        return v0_1;
    }

    private List getFeature(String arg4) {
        Object v0 = this.mFeatureMap.get(arg4);
        if (v0 == null) {
            ArrayList v0_1 = new ArrayList();
            int v1 = 1;
            if ("public".equals(arg4)) {
                this.addPublicFeature(((List) v0_1));
            } else if ("protected".equals(arg4)) {
                this.addProtectedFeature(((List) v0_1));
            } else if ("legacy".equals(arg4)) {
                this.c(((List) v0_1));
            } else {
                v1 = 0;
            }

            if (v1 == 0) {
//                goto label_3;
            } else {
                this.mFeatureMap.put(arg4, v0_1);
            }
        }

        label_3:
        return ((List) v0);
    }

    public void addPublicFeature(List<String> arg2) {
        arg2.add("config");
        arg2.add("appInfo");
        arg2.add("login");
        arg2.add("close");
        arg2.add("shareInfo");
        arg2.add("gallery");
        arg2.add("toggleGalleryBars");
        arg2.add("slideShow");
        arg2.add("relatedShow");
        arg2.add("adImageShow");
        arg2.add("adImageClick");
        arg2.add("adImageLoadFinish");
        arg2.add("toast");
        arg2.add("slideDownload");
        arg2.add("requestChangeOrientation");
        arg2.add("openCommodity");
        arg2.add("adInfo");
    }

    private void sendJsMessage(JSONObject arg5) {
        WebView v0 = this.getWebView();
        if (v0 != null) {
            String v1 = "javascript:ToutiaoJSBridge._handleMessageFromToutiao(" + arg5.toString() + ")";
            LoadUrlUtils.loadUrl(v0, v1);
            if (Logger.debug()) {
                Logger.v(JsObject.TAG, "js_msg " + v1);
            }
        }
    }

    public void b() {
        JsObject.sInsts.remove(this);
    }

    public final void b(String event_id, JSONObject params) {
        try {
            if (android.support.design.a.isTextEmpty(event_id)) {
                return;
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("__msg_type", "event");
            jsonObject.put("__event_id", event_id);
            if (params != null) {
                jsonObject.put("__params", params);
            }
            this.sendJsMessage(jsonObject);
        } catch (Exception exception) {
        }
    }

    public void c(List<String> arg2) {
        arg2.add("isAppInstalled");
        arg2.add("appInfo");
        arg2.add("login");
        arg2.add("share");
        arg2.add("open");
        arg2.add("close");
        arg2.add("gallery");
    }

    private void c(JSONObject arg3) {
        this.a(arg3);
        Object v0 = this.mContextRef != null ? this.mContextRef.get() : null;
        if (v0 != null && ((v0 instanceof Activity)) && (android.support.design.a.isComponentActive(((Context) v0))) && (this.a(((Context) v0)))) {
            ((Activity) v0).finish();
        }
    }

    public final void clearWebDownloadListeners() {
        if (this.webDownloadlisteners != null && this.getActivityCtx() != null && this.webDownloadlisteners.size() > 0) {
            Iterator<Map.Entry<Long, DownloadInfoChangeListener>> iterator = this.webDownloadlisteners.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Long, DownloadInfoChangeListener> entry = iterator.next();
                if (entry == null) {
                    continue;
                }
                DownloadAdapterProxy.inst().unregisterDownloadListener(
                        this.getActivityCtx(),
                        entry.getKey(),
                        entry.getValue());
            }

            this.webDownloadlisteners.clear();
            this.webDownloadlisteners = null;
        }
    }

    public final void checkLogMsg(String arg2) {
        if (arg2 != null && (arg2.startsWith("bytedance://"))) {
            this.reportLocalEvent(arg2);
        }
    }

    private boolean showGallery(JSONObject jsonObject) throws Exception {
        try {
            int selectedIndex = jsonObject.optInt("index", 0);
            ArrayList<ImageInfo> imageInfoList = new ArrayList();
            JSONArray imagesJSONArray = jsonObject.optJSONArray("images");
            if (imagesJSONArray != null && imagesJSONArray.length() > 0) {
                int length = imagesJSONArray.length();
                for (int i = 0; i < length; ++i) {
                    String json = imagesJSONArray.getString(i);
                    if (TTUtils.isValidUrl(json)) {
                        imageInfoList.add(new ImageInfo(json, null));
                    }
                }
            }

            JSONArray imageListJSONArray;
            if (((List) imageInfoList).isEmpty()) {
                imageListJSONArray = jsonObject.optJSONArray("image_list");
            } else {
                imageListJSONArray = null;
            }

            if (imageListJSONArray != null && imageListJSONArray.length() > 0) {
                int length = imageListJSONArray.length();
                for (int i = 0; i < length; ++i) {
                    ImageInfo imageInfo = ImageInfo.fromJson(imageListJSONArray.getJSONObject(i), false);
                    if (imageInfo != null) {
                        imageInfoList.add(imageInfo);
                    }
                }
            }

            if (selectedIndex < 0 || selectedIndex >= imageInfoList.size()) {
                selectedIndex = 0;
            }

            if (imageInfoList.isEmpty()) {
                return false;
            }

            if (this.mGalleryDisplayer == null) {
                return false;
            }

            this.mGalleryDisplayer.showLargeImage(imageInfoList, selectedIndex);
            return true;
        } catch (Exception exception) {
            if (!Logger.debug()) {
                return false;
            }
            Logger.d(JsObject.TAG, "call gallery fail: " + exception);
        }
        return false;
    }

    public final Object queryContextData(String key) {
        HashMap<String, Object> map = new HashMap();
        if (key.length() != 0) {
            Context context = this.mContextRef != null ? this.mContextRef.get() : null;
            if ((context instanceof ContextDataProvider)) {
                ((ContextDataProvider) context).queryContextData(key, map);
            }

            Fragment fragment = this.mFragmentRef != null ? this.mFragmentRef.get() : null;
            if ((fragment instanceof ContextDataProvider)) {
                ((ContextDataProvider) fragment).queryContextData(key, map);
            }

            if (this.mJsDataProvider != null) {
                this.mJsDataProvider.queryContextData(key, map);
            }
        }
        return map.get(key);
    }

    public final void onResume() {
        String v4 = null;
        int v0 = 1;
        if (!android.support.design.a.isTextEmpty(this.mPendingLoginCallbackId)) {
            Spipe v2 = Spipe.inst();
            if (android.support.design.a.isTextEmpty(this.mPendingLoginPlat)) {
                if (!v2.h()) {
                    if (!v2.d("mobile")) {
                        v0 = 0;
                    }
                }
            } else if (v2.d(this.mPendingLoginPlat)) {
            } else {
                label_24:
                v0 = 0;
            }

            try {
//                label_12:
                JSONObject v1 = new JSONObject();
                v1.put("code", v0);
                this.sendCallbackMsg(this.mPendingLoginCallbackId, v1);
            } catch (Exception v0_1) {
            }
        }

        this.mPendingLoginCallbackId = v4;
        this.mPendingLoginPlat = v4;
    }

    private void e(JSONObject arg10) {
        Object v1 = null;
        try {
            Object v0_1 = this.mContextRef != null ? this.mContextRef.get() : v1;
            boolean v2 = v0_1 instanceof Activity;
            Object v2_1 = v2 ? v0_1 : v1;
            if (v2_1 != null && (android.support.design.a.isComponentActive(((Context) v2_1)))) {
                String v0_2 = arg10.optString("type");
                if (android.support.design.a.isTextEmpty(v0_2)) {
                    return;
                }

                if (v0_2.indexOf(58) >= 0) {
                    return;
                }

                UrlBuilder v3 = new UrlBuilder("sslocal://" + v0_2);
                JSONObject v4 = arg10.optJSONObject("args");
                if (v4 != null && v4.length() > 0) {
                    Iterator v5 = v4.keys();
                    while (v5.hasNext()) {
                        v0_1 = v5.next();
                        v1 = v4.get(((String) v0_1));
                        if ((v1 instanceof Integer)) {
                            v3.addParam(((String) v0_1), ((Integer) v1).intValue());
                        } else if ((v1 instanceof Long)) {
                            v3.addParam(((String) v0_1), ((Long) v1).longValue());
                        } else if ((v1 instanceof Double)) {
                            v3.mList.add(new NameValueImpl(((String) v0_1), String.valueOf(((Double) v1).doubleValue())));
                        } else {
                            if (!(v1 instanceof String)) {
                                continue;
                            }

                            v3.addParam(((String) v0_1), ((String) v1));
                        }
                    }
                }

                v0_2 = v3.build();
                if (Logger.debug()) {
                    Logger.v(TAG, "js open: " + v0_2);
                }

                AppUtil.b(((Context) v2_1), v0_2);
            }

            return;
        } catch (Exception v0) {
            return;
        }
    }

    public final void parseMsgQueue(String message) {
        int v0_3;
        if (message == null) {
            return;
        }

        if (!message.startsWith("bytedance://")) {
            return;
        }

        String v0 = "bytedance://dispatch_message/";
        String v1 = "bytedance://private/setresult/";
        try {
            if (message.equals(v0)) {
                WebView webView = this.getWebView();
                if (webView == null) {
                    return;
                }
                LoadUrlUtils.loadUrl(webView, "javascript:ToutiaoJSBridge._fetchQueue()");
                return;
            }

            if (!message.startsWith(v1)) {
                return;
            }

            v0_3 = v1.length();
            int v1_1 = message.indexOf(38, v0_3);
            if (v1_1 <= 0) {
                return;
            }

            v0 = message.substring(v0_3, v1_1);
            v1 = message.substring(v1_1 + 1);
            if (!v0.equals("SCENE_FETCHQUEUE")) {
                return;
            }

            if (v1.length() <= 0) {
                return;
            }
            v0 = new String(Base64.decode(v1, 2));
            if (Logger.debug()) {
                Logger.d(JsObject.TAG, v0);
            }

            JSONArray v2 = new JSONArray(v0);
            int v3 = v2.length();
            v0_3 = 0;
            while (true) {
                label_42:
                if (v0_3 >= v3) {
                    return;
                }

                JSONObject jsonObject = v2.getJSONObject(v0_3);
                JSMessage jsMessage = new JSMessage();
                jsMessage.msgType = jsonObject.getString("__msg_type");
                jsMessage.callbackId = jsonObject.optString("__callback_id", null);
                jsMessage.func = jsonObject.optString("func");
                jsMessage.params = jsonObject.optJSONObject("params");
                jsMessage.jssdk = jsonObject.optInt("JSSDK");
                if (!android.support.design.a.isTextEmpty(jsMessage.msgType) && !android.support.design.a.isTextEmpty(jsMessage.func)) {
                    Message msg = this.mWeakHandler.obtainMessage(11);
                    msg.obj = jsMessage;
                    this.mWeakHandler.sendMessage(msg);
                }
                ++v0_3;
                continue;
            }
        } catch (Exception exception) {
            if (Logger.debug()) {
                Logger.w(JsObject.TAG, "failed to parse jsbridge msg queue " + v1);
                return;
            }

            Logger.w(JsObject.TAG, "failed to parse jsbridge msg queue");
        }
    }

    @JavascriptInterface
    public boolean reportLocalEvent(String arg5) {
        boolean v0 = false;
        Logger.d(JsObject.TAG, "reportLocalEvent: " + arg5);
        if (this.mAppData != null && !android.support.design.a.isTextEmpty(arg5)) {
            try {
                Uri v1_1 = Uri.parse(arg5);
                if (!JsObject.canHandleUri(v1_1)) {
                    return v0;
                }

                v0 = true;
                Message v2 = this.mWeakHandler.obtainMessage(10);
                v2.obj = v1_1;
                this.mWeakHandler.sendMessage(v2);
            } catch (Exception v1) {
            }
        }

        return v0;
    }

    private boolean f(JSONObject arg10) throws Exception {
        boolean v0_2;
        Intent v0_1;
        String v1 = null;
        String v5 = arg10 != null ? arg10.optString("pkg_name") : v1;
        String v0 = arg10 != null ? arg10.optString("pkg_class") : v1;
        Activity v6 = this.getActivityCtx();
        if (v6 != null && !android.support.design.a.isTextEmpty(v5)) {
            boolean v7 = v5.equals(((Context) v6).getPackageName());
            if (!android.support.design.a.isTextEmpty(v0)) {
                Intent v4 = new Intent();
                v4.setComponent(new ComponentName(v5, v0));
                v4.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                v0_1 = !ToolUtils.isInstalledApp(((Context) v6), v4) ? null : v4;
            } else {
                v0_1 = null;
            }

            if (v0_1 == null && (v7)) {
                v0_2 = true;
                return v0_2;
            }

            if (v0_1 == null) {
                v0_1 = ToolUtils.getLaunchIntentForPackage(((Context) v6), v5);
            }

            if (v0_1 != null) {
                try {
                    ((Context) v6).startActivity(v0_1);
                    return true;
                } catch (Exception v0_3) {
                }
            }

            v0_2 = false;
        } else {
            v0_2 = false;
        }

        return v0_2;
    }

    public final void onGeolocationPermissionsHidePrompt() {
        Object v0 = this.mGeoDlg != null ? this.mGeoDlg.get() : null;
        if (v0 != null && (((AlertDialog) v0).isShowing())) {
            ((AlertDialog) v0).dismiss();
        }
    }

    public final WebView getWebView() {
        Object v0 = null;
        if (this.b != null) {
            v0 = this.b.get();
        }
        return ((WebView) v0);
    }

    public final Activity getActivityCtx() {
        Activity v0_1 = null;
        Object v0 = this.mContextRef != null ? this.mContextRef.get() : null;
        if (v0 == null) {
            v0_1 = null;
        } else if ((v0 instanceof Activity)) {
            v0_1 = (Activity) v0;
        } else {
            v0_1 = null;
        }

        return v0_1;
    }

    public void handleMsg(Message message) {
        List v1_2;
        int v1_1;
        boolean v6;
        k v5_1;
        JSONObject v4;
        Object v0_1;
        String v1 = null;
        int v2 = 1;
        if (message == null) {
            return;
        }

        switch (message.what) {
            case 10: {
                try {
                    label_8:
                    if ((message.obj instanceof Uri)) {
                        v0_1 = message.obj;
                    } else {
                        v0_1 = v1;
                    }

                    label_12:
                    if (v0_1 == null) {
                        return;
                    }

                    this.handleUri(((Uri) v0_1));
                } catch (Exception v0) {
//            label_16:
                }
            }
            case 11: {
                label_17:
                if (!(message.obj instanceof JSMessage)) {
                    return;
                }

                try {
                    v0_1 = message.obj;
                    if (!"call".equals(((JSMessage) v0_1).msgType)) {
                        return;
                    }

                    v4 = new JSONObject();
                    if ("config".equals(((JSMessage) v0_1).func)) {
                        this.mPendingConfigKey = null;
                        this.mPendingConfigCallback = null;
                        if (android.support.design.a.isTextEmpty(((JSMessage) v0_1).callbackId)) {
                            return;
                        }

                        if (!this.config(((JSMessage) v0_1).callbackId, ((JSMessage) v0_1).params, v4)) {
                            return;
                        }

                        this.sendCallbackMsg(((JSMessage) v0_1).callbackId, v4);
                        return;
                    }

                    WebView v5 = this.getWebView();
                    if (v5 != null) {
                        v1 = v5.getUrl();
                    }

                    v5_1 = this.mLastConfigItem;
                    v6 = this.a(v1);
                    if (!v6) {
                        v1_1 = this.mAppData.mForceJSPermission > 0 ? 1 : 0;
                        if (v1_1 != 0 || ((JSMessage) v0_1).jssdk >= 2) {
                            if (v5_1 != null && (v5_1.b.contains(((JSMessage) v0_1).func))) {
                                v1_1 = 1;
//                        goto label_79;
                            } else {
                                v1_1 = 0;
                            }
                        } else {
                            v1_2 = this.getFeature("legacy");
                            if (v1_2 != null && (v1_2.contains(((JSMessage) v0_1).func))) {
                                v1_1 = 1;
//                        goto label_79;
                            } else {
                                v1_1 = 0;
                            }
                        }

                        label_79:
                        if (v1_1 != 0) {
                            v2 = v1_1;
                        } else {
                            v1_2 = this.getFeature("public");
                            if (v1_2 != null && (v1_2.contains(((JSMessage) v0_1).func))) {
//                    goto label_53;
                            } else {
                                v2 = 0;
                            }
                        }
                    }

//            goto label_53;

                    if ("appInfo".equals(((JSMessage) v0_1).func)) {
                        if (android.support.design.a.isTextEmpty(((JSMessage) v0_1).callbackId)) {
                            return;
                        }

                        this.getAppInfo(v4, ((JSMessage) v0_1).jssdk, v5_1, v6);
                        this.sendCallbackMsg(((JSMessage) v0_1).callbackId, v4);
                        return;
                    }

                    if (v2 == 0) {
                        v4.put("code", -1);
                        this.sendCallbackMsg(((JSMessage) v0_1).callbackId, v4);
                        return;
                    }

                    boolean v1_3 = this.processJsMsg(((JSMessage) v0_1), v4);
                    if (android.support.design.a.isTextEmpty(((JSMessage) v0_1).callbackId)) {
                        return;
                    }

                    if (!v1_3) {
                        return;
                    }

                    this.sendCallbackMsg(((JSMessage) v0_1).callbackId, v4);
                    return;
                } catch (Exception v0) {
                    return;
                }
            }
            case 12: {
                label_117:
                if (!(message.obj instanceof ShareBean)) {
                    return;
                }

                Object v1_4 = null;
                v0_1 = message.obj;
                if (((ShareBean) v0_1).g != null) {
                    v1_4 = ((ShareBean) v0_1).g.get();
                }

                if (v1_4 != null && (((ProgressDialog) v1_4).isShowing())) {
                    ((ProgressDialog) v1_4).dismiss();
                }

                if (!android.support.design.a.isComponentActive(this.getActivityCtx())) {
                    return;
                }

                if (((ShareBean) v0_1).a != this.mPendingShareId) {
                    return;
                }

                ++this.mPendingShareId;
                this.doShare(((ShareBean) v0_1));
                return;
            }
        }

        return;


    }

    private boolean initWx() {
        boolean v0;
        Context context = null;
        if (this.mWxApi != null) {
            return true;
        }

        if (this.B) {
            return false;
        }

        if (this.mContextRef != null) {
            context = this.mContextRef.get();
        }

        if (context == null) {
            return false;
        }

        this.B = true;
        String v0_1 = this.mAppData.cc;
        if (!android.support.design.a.isTextEmpty(v0_1)) {
            long v4 = System.currentTimeMillis();
            try {
                this.mWxApi = WXAPIFactory.createWXAPI(((Context) context), v0_1, true);
                if (!this.mWxApi.registerApp(v0_1)) {
                    this.mWxApi = null;
                }
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
            Logger.d(JsObject.TAG, "init Wx: " + (System.currentTimeMillis() - v4));
        }

        v0 = this.mWxApi != null ? true : false;
        if (!v0) {
            String v2 = AppLog.g(context);
            String v3 = v2 == null ? "failed_to_get_signature_hash" : "signature_hash " + v2;
            MobClickCombiner.onEvent(context, "weixin_share", v3, 0, System.currentTimeMillis());
        }
        return v0;
    }

    private boolean isWXAppInstalled() {
        boolean v0 = false;
        if (this.mContextRef != null && this.mContextRef.get() != null) {
            if (this.mWxApi != null) {
                v0 = this.mWxApi.isWXAppInstalled();
            } else {
                String v1 = this.mAppData.cc;
                if (!android.support.design.a.isTextEmpty(v1)) {
                    this.mWxApi = WXAPIFactory.createWXAPI((Context) this.mContextRef.get(), v1, true);
                    v0 = this.mWxApi.isWXAppInstalled();
                }
            }
        }

        return v0;
    }

    public interface ContextDataProvider {
        void queryContextData(String key, HashMap<String, Object> arg2);
    }

    public interface GalleryDisplayer {
        void showLargeImage(List<ImageInfo> imageInfoList, int selectedIndex);
    }

    final class i$a implements DownloadInfoChangeListener {
        private final JsObject b;
        private int a;

        i$a(JsObject arg2) {
            this.b = arg2;

            this.a = 0;
        }

        public final void setDownloadId(long id) {
        }

        public final void onDownloadProgressChanged(DownloadShortInfo arg8, int arg9, long arg10, long arg12, long arg14) {
            WebView v0_1;
            int v6 = 3;
            int v0 = 0;
            if (arg8 != null && this.b.getActivityCtx() != null) {
                String v1 = DownloadAdapterProxy.inst().getDownloadExtra(this.b.getActivityCtx(), arg8.id);
                if (!android.support.design.a.isTextEmpty(v1)) {
                    String[] v1_1 = v1.split("##");
                    if (v1_1 != null && v1_1.length > 0) {
                        v1 = v1_1[0];
                        if (arg9 == v6 && arg8.b == 8) {
                            v0_1 = this.b.getWebView();
                            if (v0_1 != null) {
                                v0_1.loadUrl("javascript:onGameComplete(\'" + v1 + "\')");
                            } else {
                            }

                            return;
                        }

                        if (arg10 <= 0) {
                            return;
                        }

                        int v2 = ((int) (100 * arg12 / arg10));
                        if (v2 - this.a >= 20 || this.a == 0 && v2 >= v6) {
                            this.a = v2;
                            v0 = 1;
                        }

                        if (v0 == 0) {
                            return;
                        }

                        v0_1 = this.b.getWebView();
                        if (v0_1 == null) {
                            return;
                        }

                        if (android.support.design.a.isTextEmpty(v1)) {
                            return;
                        }

                        v0_1.loadUrl("javascript:onGameProgress(\'" + v1 + "\',\'" + v2 + "\')");
                        return;
                    }

                    DownloadAdapterProxy.inst().unregisterDownloadListener(this.b.getActivityCtx(), Long.valueOf(arg8.id), ((DownloadInfoChangeListener) this));
                    this.b.webDownloadlisteners.remove(Long.valueOf(arg8.id));
                }
            }
        }
    }

    public final class JSMessage {
        public String msgType;
        public String callbackId;
        public String func;
        public JSONObject params;
        public int jssdk;
    }

    public static final class ShareBean {
        public int a;
        public String platform;
        public String title;
        public String desc;
        public String image;
        public String url;
        public WeakReference g;
        public byte[] h;
        public String i;

        public ShareBean() {

        }

        public final void fromJSONObject(JSONObject jo) throws JSONException {
            if (jo != null) {
                this.platform = jo.getString("platform");
                this.title = jo.getString("title");
                this.desc = jo.optString("desc");
                this.image = jo.optString("image");
                this.url = jo.optString("url");
            }
        }
    }

    final class f extends AsyncTask {
        private ShareBean a;
        private Context b;
        private Handler c;

        public f(Context arg1, Handler arg2, ShareBean arg3) {

            this.b = arg1;
            this.c = arg2;
            this.a = arg3;
        }

        private Void a() {
            Bitmap v0_2 = null;
            String v2;
            boolean v0 = false;
            Void v10 = null;
            int v11;
            try {
                v2 = this.a.image;
                if ("weixin".equals(this.a.platform)) {
                    v11 = 1;
                } else if (!"weixin_moments".equals(this.a.platform)) {
                    v11 = 0;
                } else {
                    v11 = 1;
                }

                if (TTUtils.isValidUrl(v2)) {
                    BaseImageManager v1 = new BaseImageManager(this.b);
                    String v3 = com.bytedance.common.utility.aa.md5(v2);
                    String v12 = v1.getExternalCacheFile(v3);
                    String v6 = BaseImageManager.getCacheFileName(v3);
                    String v4 = v1.getExternalImageSaveDir(v6);
                    if (BaseImageManager.isExternalStorageMounted()) {
                        File v13 = new File(v12);
                        v0 = v13.isFile();
                        if (!v0) {
                            v0 = AppUtil.downloadImage(this.b, 512000, v2, (String) null, v4, null, v6, null, null, null);
                            if (v0) {
                                v0 = v13.isFile();
                            }
                        }
                    }

                    if (!v0) {
                        v0_2 = null;
                    } else if (v11 != 0) {
                        v0_2 = android.support.design.a.decodeFile(v12, 150, 150, null);
//                        goto label_47;
                    } else {
                        this.a.i = v12;
                        v0_2 = null;
                    }
                } else {

                }

                if (v11 == 0) {
                    this.c.sendMessage(this.c.obtainMessage(12, this.a));
                    return v10;
                }

                if (v0_2 == null) {
                    this.c.sendMessage(this.c.obtainMessage(12, this.a));
                    return v10;
                }

                ByteArrayOutputStream v1_1 = new ByteArrayOutputStream();
                v0_2.compress(Bitmap.CompressFormat.JPEG, 85, ((OutputStream) v1_1));
                byte[] v2_1 = v1_1.toByteArray();
                if (v2_1 != null) {
                    this.a.h = v2_1;
                }

                v1_1.close();
                v0_2.recycle();
            } catch (Throwable v0_1) {
                v0_1.printStackTrace();
            }

            label_60:
            this.c.sendMessage(this.c.obtainMessage(12, this.a));
            return v10;
        }

        protected final Object doInBackground(Object[] arg2) {
            return this.a();
        }
    }
}

